(function(a){
    var pics,prev,next;
    var speed=180;
    a.picscroll=function(opt){
        pics=opt.pics;
        prev=opt.prev;
        next=opt.next;
        $(prev).parent().on('click',function(e){
            move($(e.target));
        });
    };

    function move(obj) {
        var oUl=obj.parent().find(pics);
        var left=parseInt(oUl.css('margin-left'));
        if('.'+obj.attr('class')==prev){
            if(-left>speed){
                oUl.stop().animate({'margin-left': left+speed + "px"},'fast');
            }else{
                oUl.stop().animate({'margin-left': 0+ "px"},'fast');
            }
        }else if('.'+obj.attr('class')==next){
            var ulwidth=parseInt(oUl.css('width'));
            var wrapwidth=parseInt(oUl.parent().css('width'));
            var fix=10*oUl.find('li').length;
            var a=ulwidth-wrapwidth+left;
            if(a>speed){
                oUl.stop().animate({'margin-left': left-speed + "px"},'fast');
            }else{
                oUl.stop().animate({'margin-left':wrapwidth-ulwidth+fix + "px"},'fast');
            }
        }
    }
})(window);